package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CpProject;
import com.ruoyi.system.service.ICpProjectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 新增参赛项目Controller
 *
 * @author zhangjinlei
 * @date 2022-05-12
 */
@RestController
@RequestMapping("/system/project")
public class CpProjectController extends BaseController
{
    @Autowired
    private ICpProjectService cpProjectService;

    /**
     * 查询新增参赛项目列表
     */
    @PreAuthorize("@ss.hasPermi('system:project:list')")
    @GetMapping("/list")
    public TableDataInfo list(CpProject cpProject)
    {
        startPage();
        List<CpProject> list = cpProjectService.selectCpProjectList(cpProject);
        return getDataTable(list);
    }

    /**
     * 获取比赛项目信息
     */
    @GetMapping("/queryProjectInfo")
    public TableDataInfo  queryProjectInfo (CpProject cpProject){
        List<CpProject> queryProjectInfoList = cpProjectService.queryProjectInfoList();
        return getDataTable(queryProjectInfoList);
    }
    /**
     * 导出新增参赛项目列表
     */
    @PreAuthorize("@ss.hasPermi('system:project:export')")
    @Log(title = "新增参赛项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CpProject cpProject)
    {
        List<CpProject> list = cpProjectService.selectCpProjectList(cpProject);
        ExcelUtil<CpProject> util = new ExcelUtil<CpProject>(CpProject.class);
        util.exportExcel(response, list, "新增参赛项目数据");
    }

    /**
     * 获取新增参赛项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:project:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cpProjectService.selectCpProjectById(id));
    }

    /**
     * 新增新增参赛项目
     */
    @PreAuthorize("@ss.hasPermi('system:project:add')")
    @Log(title = "新增参赛项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CpProject cpProject)
    {
        return toAjax(cpProjectService.insertCpProject(cpProject));
    }

    /**
     * 修改新增参赛项目
     */
    @PreAuthorize("@ss.hasPermi('system:project:edit')")
    @Log(title = "新增参赛项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CpProject cpProject)
    {
        return toAjax(cpProjectService.updateCpProject(cpProject));
    }

    /**
     * 删除新增参赛项目
     */
    @PreAuthorize("@ss.hasPermi('system:project:remove')")
    @Log(title = "新增参赛项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cpProjectService.deleteCpProjectByIds(ids));
    }
}
